package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.DateUtil;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;
import io.lkt.modules.job.utils.HttpGetPostUtils;
import io.lkt.modules.sys.dao.BBrandPromotionSettleInfoDao;
import io.lkt.modules.sys.dao.BOrderInfoDao;
import io.lkt.modules.sys.dao.BUserInfoDao;
import io.lkt.modules.sys.dao.BrandPromotionPayUserInfoDao;
import io.lkt.modules.sys.dao.SysUserGzhDao;
import io.lkt.modules.sys.entity.*;
import io.lkt.modules.sys.service.*;
import io.lkt.modules.sys.shiro.WeixinService;
import java.io.IOException;
import java.util.*;

import lombok.Synchronized;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage.WxMpTemplateMessageBuilder;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service("bOrderInfoService")
public class BOrderInfoServiceImpl
        extends ServiceImpl<BOrderInfoDao, BOrderInfoEntity>
        implements BOrderInfoService
{
    @Autowired
    private BOrderInfoDao bOrderInfoDao;
    @Autowired
    private BUserInfoDao bUserInfoDao;
    @Autowired
    private BUserInfoService bUserInfoService;
    @Autowired
    private BUserVipValidService userVipValidService;

    @Autowired
    private SysUserGzhDao sysUserGzhDao;
    @Autowired
    private BUserPromotionSettleInfoService bUserPromotionSettleInfoService;
    @Autowired
    private BUserInviteIncomeInfoService bUserInviteIncomeInfoService;
    @Autowired
    private BBrandPromotionSettleInfoDao brandPromotionSettleInfoDao;
    @Autowired
    private BrandPromotionPayUserInfoDao brandPromotionPayUserInfoDao;
    @Value("${serviceUrls}")
    private String serviceUrls;

    public PageUtils queryPage(Map<String, Object> params)
    {
        IPage<BOrderInfoEntity> page = page(new Query()
                .getPage(params), new QueryWrapper());

        return new PageUtils(page);
    }

    public List<BOrderInfoEntity> queryList(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryList(map);
    }

    public List<BOrderVitalEntity> queryVital(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryVital(map);
    }

    public BOrderVitalEntity queryVitalSum(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryVitalSum(map);
    }

    public BOrderVitalEntity queryVitalRefundSum(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryVitalRefundSum(map);
    }

    @Override
    public Integer queryPrepayTotal(Map<String, Object> map) {
        return bOrderInfoDao.queryPrepayTotal(map);
    }

    @Override
    public BOrderInfoEntity getLatestPrepayOrder(Map<String, Object> params) {
        return bOrderInfoDao.getLatestPrepayOrder(params);
    }

    @Override
    public void updateFollowStatus(String orderId, Date followTime, Long followDuration, Long userId, String remark) {
        bOrderInfoDao.updateFollowStatus(orderId, followTime, followDuration, userId, remark);
    }

    @Override
    public List<SysUserEntity> getValidFollowOrderSummaryList(Map<String, Object> params) {
        return bOrderInfoDao.getValidFollowOrderSummaryList(params);
    }

    @Override
    public List<SysUserEntity> getValidDealedOrderSummaryList(Map<String, Object> params) {
        return bOrderInfoDao.getValidDealedOrderSummaryList(params);
    }

    @Override
    public List<SysUserEntity> getSysUserFollowList(Map<String, Object> params) {
        return bOrderInfoDao.getSysUserFollowList(params);
    }

    @Override
    public Integer getSysUserFollowListTotal(Map<String, Object> params) {
        return bOrderInfoDao.getSysUserFollowListTotal(params);
    }

    @Override
    public List<String> getSysUserFollowOrderIdList(Map<String, Object> params) {
        return bOrderInfoDao.getSysUserFollowOrderIdList(params);
    }

    @Override
    public List<String> getSysUserDealedOrderIdList(Map<String, Object> params) {
        return bOrderInfoDao.getSysUserDealedOrderIdList(params);
    }

    @Override
    public List<BOrderInfoEntity> getfollowInfoByUserId(Map<String, Object> params) {
        return bOrderInfoDao.getfollowInfoByUserId(params);
    }

    @Override
    public List<VipOrderAnalyseEntity> getGzhVipOrderAnalyse(Map<String, Object> params) {
        return bOrderInfoDao.getGzhVipOrderAnalyse(params);
    }

    @Override
    public List<VipOrderAnalyseEntity> getSummaryVipOrderAnalyse(Map<String, Object> params) {
        return bOrderInfoDao.getSummaryVipOrderAnalyse(params);
    }

    public Integer queryTotal(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryTotal(map);
    }

    public Integer queryVitelTotal(Map<String, Object> map)
    {
        return this.bOrderInfoDao.queryVitelTotal(map);
    }

    public int addOrder(BOrderInfoEntity bOrderInfoEntity)
    {
        return this.bOrderInfoDao.addOrder(bOrderInfoEntity);
    }

    public BOrderInfoEntity getInfo(String id)
    {
        return this.bOrderInfoDao.getInfo(id);
    }

    public void drawback(BOrderInfoEntity bOrderInfoEntity)
    {
        this.bOrderInfoDao.drawback(bOrderInfoEntity.getOrderId());
        this.bUserInfoDao.closeVip(bOrderInfoEntity.getUserId());
        userVipValidService.closeVipEndTime(bOrderInfoEntity.getUserId());

        BUserInfoEntity userInfo = (BUserInfoEntity)this.bUserInfoService.getById(bOrderInfoEntity.getUserId());
        BOrderInfoEntity order = this.bOrderInfoDao.getInfo(bOrderInfoEntity.getOrderId());
        try
        {
            if ((order != null) && (order.getTotalAmount().doubleValue() > 0.0D) &&
                    (userInfo != null) && (userInfo.getReferer() != null) && (userInfo.getReferer().intValue() > 0)) {
                backIncome1(userInfo.getReferer(), order.getTotalAmount(), userInfo);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        if ((userInfo != null) && (userInfo.getOpenId() != null) && (userInfo.getConcernStatus().equals(Integer.valueOf(1))) && (order != null))
        {
            SysGzhEntity sysGzh = this.sysUserGzhDao.getGzhByCode(userInfo.getGzhCode());

            WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(userInfo.getOpenId()).templateId(sysGzh.getRefundTempId()).build();
            String firstMsg = sysGzh.getGzhName() + "提醒您，您有一笔退款成功，请留意。\n\n";
            String remarkMsg = "查退款方法/步骤：\n" +
                    "点击微信首页右下角【我】\n" +
                    "在【我】->【支付】->【钱包】->【账单】->正上方【全部交易类型】->【有退款】\n" +
                    "列表显示有退款记录了\n" +
                    "如有疑问，请回复【客服】咨询服务。";

            templateMessage.addData(new WxMpTemplateData("first", firstMsg, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", order.getOrderId(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", order.getTotalAmount() + "元", "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg, "#0000FF"));
            String msgId = null;
            try
            {
                WxMpServiceImpl wxMpService = WeixinService.getWeixinService(sysGzh);

                msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
            }
            catch (WxErrorException e)
            {
                e.printStackTrace();
            }
        }
        try
        {
            if ((order != null) && (order.getTotalAmount().doubleValue() > 0.0D))
            {
                BrandPromotionPayUserInfoEntity brandPromotionPayUserInfo = this.brandPromotionPayUserInfoDao.getBPPUIByOrderId(order.getOrderId());
                if (brandPromotionPayUserInfo != null)
                {
                    BBrandPromotionSettleInfoEntity bBrandPromotionSettleInfo = this.brandPromotionSettleInfoDao.getBrandPromotionSettleInfoByUserId(brandPromotionPayUserInfo.getBrandAgentId());
                    if (bBrandPromotionSettleInfo != null)
                    {
                        int commissionProportion = ((Integer)Optional.ofNullable(bBrandPromotionSettleInfo.getCommissionProportion()).orElse(Integer.valueOf(0))).intValue();
                        if (commissionProportion > 0)
                        {
                            double commissionIncome = order.getTotalAmount().doubleValue() * commissionProportion / 100.0D;
                            double cumulativeIncome = ((Double)Optional.ofNullable(bBrandPromotionSettleInfo.getCumulativeIncome()).orElse(Double.valueOf(0.0D))).doubleValue();

                            BBrandPromotionSettleInfoEntity finalBrandPromotionSettleInfo = new BBrandPromotionSettleInfoEntity();
                            finalBrandPromotionSettleInfo.setId(bBrandPromotionSettleInfo.getId());
                            finalBrandPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome - commissionIncome));
                            finalBrandPromotionSettleInfo.setModifyTime(DateUtil.getCurDate());
                            this.brandPromotionSettleInfoDao.updateById(finalBrandPromotionSettleInfo);

                            BrandPromotionPayUserInfoEntity newBrandPromotionPayUserInfo = new BrandPromotionPayUserInfoEntity();
                            newBrandPromotionPayUserInfo.setBrandId(brandPromotionPayUserInfo.getBrandId());
                            newBrandPromotionPayUserInfo.setUserId(brandPromotionPayUserInfo.getUserId());
                            newBrandPromotionPayUserInfo.setPayAmount(Double.valueOf(-brandPromotionPayUserInfo.getPayAmount().doubleValue()));
                            newBrandPromotionPayUserInfo.setPayDesc("退款");
                            newBrandPromotionPayUserInfo.setCreateTime(DateUtil.getCurDate());
                            newBrandPromotionPayUserInfo.setBrandAgentId(brandPromotionPayUserInfo.getBrandAgentId());
                            newBrandPromotionPayUserInfo.setOrderId(brandPromotionPayUserInfo.getOrderId());
                            this.brandPromotionPayUserInfoDao.insert(newBrandPromotionPayUserInfo);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    private void backIncome1(Integer refererUserId, Double totalAmount, BUserInfoEntity userInfo)
    {
        BUserInfoEntity referer = (BUserInfoEntity)this.bUserInfoService.getById(refererUserId);
        if (referer != null)
        {
            BUserPromotionSettleInfoEntity refererPromotionSettleInfo = this.bUserPromotionSettleInfoService.queryByUser(referer.getUserId());
            if ((refererPromotionSettleInfo != null) && (refererPromotionSettleInfo.getFirstLevelProportion().doubleValue() > 0.0D))
            {
                double vipSerivceBonus = Double.valueOf(totalAmount.doubleValue() * (refererPromotionSettleInfo.getFirstLevelProportion().doubleValue() / 100.0D)).doubleValue();
                double accountBalance = referer.getAccountBalance().doubleValue() - vipSerivceBonus;

                double firstLevelCumulativeIncome = refererPromotionSettleInfo.getFirstLevelCumulativeIncome().doubleValue() - vipSerivceBonus;
                double cumulativeIncome = refererPromotionSettleInfo.getCumulativeIncome().doubleValue() - vipSerivceBonus;
                refererPromotionSettleInfo.setFirstLevelCumulativeIncome(Double.valueOf(firstLevelCumulativeIncome > 0.0D ? firstLevelCumulativeIncome : 0.0D));
                refererPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome > 0.0D ? cumulativeIncome : 0.0D));
                this.bUserPromotionSettleInfoService.updateById(refererPromotionSettleInfo);

                backAccountBalance(referer.getUserId(), referer
                                .getAccountBalance(),
                        Double.valueOf(accountBalance > 0.0D ? accountBalance : 0.0D),
                        Double.valueOf(-vipSerivceBonus), userInfo,

                        Integer.valueOf(1),
                        Integer.valueOf(refererPromotionSettleInfo.getFirstLevelProportion().intValue()), totalAmount);

                try
                {
                    //退款推送 Start 20210113 hyl
                    /*
                    if ((referer != null) && (referer.getOpenId() != null) && (referer.getConcernStatus().equals(Integer.valueOf(1))) )
                    {
                        SysGzhEntity sysGzh = this.sysUserGzhDao.getGzhByCode(userInfo.getGzhCode());

                        WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(referer.getOpenId()).templateId(sysGzh.getRefundTempId()).build();
                        String firstMsg = referer.getNickName() + "，您邀请的用户["+userInfo.getNickName()+"]已经申请退款，您账户的奖励金"+vipSerivceBonus+"元也相应退回，请您知悉！";
                        String remarkMsg = "账户当前奖励金为"+accountBalance+"元";

                        templateMessage.addData(new WxMpTemplateData("first", firstMsg, "#FF00FF"))
                                .addData(new WxMpTemplateData("keyword1", "-", "#A9A9A9"))
                                .addData(new WxMpTemplateData("keyword2", vipSerivceBonus + "元", "#A9A9A9"))
                                .addData(new WxMpTemplateData("remark", remarkMsg, "#0000FF"));
                        String msgId = null;
                        try
                        {
                            WxMpServiceImpl wxMpService = WeixinService.getWeixinService(sysGzh);

                            msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
                        }
                        catch (WxErrorException e)
                        {
                            e.printStackTrace();
                        }
                    }
                    */
                    //退款推送 End

                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInviteIncomeInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserPromotionSettleInfoMapper");
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            if ((referer.getReferer() != null) && (referer.getReferer().intValue() > 0)) {
                backIncome2(referer.getReferer(), totalAmount, userInfo);
            }
        }
    }

    private void backIncome2(Integer refererUserId, Double totalAmount, BUserInfoEntity userInfo)
    {
        BUserInfoEntity referer = (BUserInfoEntity)this.bUserInfoService.getById(refererUserId);
        if (referer != null)
        {
            BUserPromotionSettleInfoEntity refererPromotionSettleInfo = this.bUserPromotionSettleInfoService.queryByUser(referer.getUserId());
            if ((refererPromotionSettleInfo != null) && (refererPromotionSettleInfo.getSecondLevelProportion().doubleValue() > 0.0D))
            {
                double vipSerivceBonus = Double.valueOf(totalAmount.doubleValue() * (refererPromotionSettleInfo.getSecondLevelProportion().doubleValue() / 100.0D)).doubleValue();
                double accountBalance = referer.getAccountBalance().doubleValue() - vipSerivceBonus;

                double secondLevelCumulativeIncome = refererPromotionSettleInfo.getSecondLevelCumulativeIncome().doubleValue() - vipSerivceBonus;
                double cumulativeIncome = refererPromotionSettleInfo.getCumulativeIncome().doubleValue() - vipSerivceBonus;
                refererPromotionSettleInfo.setSecondLevelCumulativeIncome(Double.valueOf(secondLevelCumulativeIncome > 0.0D ? secondLevelCumulativeIncome : 0.0D));
                refererPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome > 0.0D ? cumulativeIncome : 0.0D));
                this.bUserPromotionSettleInfoService.updateById(refererPromotionSettleInfo);

                backAccountBalance(referer.getUserId(), referer
                                .getAccountBalance(),
                        Double.valueOf(accountBalance > 0.0D ? accountBalance : 0.0D),
                        Double.valueOf(-vipSerivceBonus), userInfo,

                        Integer.valueOf(2),
                        Integer.valueOf(refererPromotionSettleInfo.getSecondLevelProportion().intValue()), totalAmount);
                try
                {
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInviteIncomeInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserPromotionSettleInfoMapper");
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            if ((referer.getReferer() != null) && (referer.getReferer().intValue() > 0)) {
                backIncome3(referer.getReferer(), totalAmount, userInfo);
            }
        }
    }

    private void backIncome3(Integer refererUserId, Double totalAmount, BUserInfoEntity userInfo)
    {
        BUserInfoEntity referer = (BUserInfoEntity)this.bUserInfoService.getById(refererUserId);
        if (referer != null)
        {
            BUserPromotionSettleInfoEntity refererPromotionSettleInfo = this.bUserPromotionSettleInfoService.queryByUser(referer.getUserId());
            if ((refererPromotionSettleInfo != null) && (refererPromotionSettleInfo.getThirdLevelProportion().doubleValue() > 0.0D))
            {
                double vipSerivceBonus = Double.valueOf(totalAmount.doubleValue() * (refererPromotionSettleInfo.getThirdLevelProportion().doubleValue() / 100.0D)).doubleValue();
                double accountBalance = referer.getAccountBalance().doubleValue() - vipSerivceBonus;

                double thirdLevelCumulativeIncome = refererPromotionSettleInfo.getThirdLevelCumulativeIncome().doubleValue() - vipSerivceBonus;
                double cumulativeIncome = refererPromotionSettleInfo.getCumulativeIncome().doubleValue() - vipSerivceBonus;
                refererPromotionSettleInfo.setThirdLevelCumulativeIncome(Double.valueOf(thirdLevelCumulativeIncome > 0.0D ? thirdLevelCumulativeIncome : 0.0D));
                refererPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome > 0.0D ? cumulativeIncome : 0.0D));
                this.bUserPromotionSettleInfoService.updateById(refererPromotionSettleInfo);

                backAccountBalance(referer.getUserId(), referer
                                .getAccountBalance(),
                        Double.valueOf(accountBalance > 0.0D ? accountBalance : 0.0D),
                        Double.valueOf(-vipSerivceBonus), userInfo,

                        Integer.valueOf(3),
                        Integer.valueOf(refererPromotionSettleInfo.getThirdLevelProportion().intValue()), totalAmount);
                try
                {
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInviteIncomeInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserPromotionSettleInfoMapper");
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            if ((referer.getReferer() != null) && (referer.getReferer().intValue() > 0)) {
                backIncome4(referer.getReferer(), totalAmount, userInfo);
            }
        }
    }

    private void backIncome4(Integer refererUserId, Double totalAmount, BUserInfoEntity userInfo)
    {
        BUserInfoEntity referer = (BUserInfoEntity)this.bUserInfoService.getById(refererUserId);
        if (referer != null)
        {
            BUserPromotionSettleInfoEntity refererPromotionSettleInfo = this.bUserPromotionSettleInfoService.queryByUser(referer.getUserId());
            if ((refererPromotionSettleInfo != null) && (refererPromotionSettleInfo.getFourthLevelProportion().intValue() > 0))
            {
                double vipSerivceBonus = Double.valueOf(totalAmount.doubleValue() * (refererPromotionSettleInfo.getFourthLevelProportion().doubleValue() / 100.0D)).doubleValue();
                double accountBalance = referer.getAccountBalance().doubleValue() - vipSerivceBonus;

                double fourthLevelCumulativeIncome = refererPromotionSettleInfo.getFourthLevelCumulativeIncome().doubleValue() - vipSerivceBonus;
                double cumulativeIncome = refererPromotionSettleInfo.getCumulativeIncome().doubleValue() - vipSerivceBonus;
                refererPromotionSettleInfo.setFourthLevelCumulativeIncome(Double.valueOf(fourthLevelCumulativeIncome > 0.0D ? fourthLevelCumulativeIncome : 0.0D));
                refererPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome > 0.0D ? cumulativeIncome : 0.0D));
                this.bUserPromotionSettleInfoService.updateById(refererPromotionSettleInfo);

                backAccountBalance(referer.getUserId(), referer
                                .getAccountBalance(),
                        Double.valueOf(accountBalance > 0.0D ? accountBalance : 0.0D),
                        Double.valueOf(-vipSerivceBonus), userInfo,

                        Integer.valueOf(4),
                        Integer.valueOf(refererPromotionSettleInfo.getFourthLevelProportion().intValue()), totalAmount);
                try
                {
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInviteIncomeInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserPromotionSettleInfoMapper");
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            if ((referer.getReferer() != null) && (referer.getReferer().intValue() > 0)) {
                backIncome5(referer.getReferer(), totalAmount, userInfo);
            }
        }
    }

    private void backIncome5(Integer refererUserId, Double totalAmount, BUserInfoEntity userInfo)
    {
        BUserInfoEntity referer = (BUserInfoEntity)this.bUserInfoService.getById(refererUserId);
        if (referer != null)
        {
            BUserPromotionSettleInfoEntity refererPromotionSettleInfo = this.bUserPromotionSettleInfoService.queryByUser(referer.getUserId());
            if ((refererPromotionSettleInfo != null) && (refererPromotionSettleInfo.getFifthLevelProportion().intValue() > 0))
            {
                double vipSerivceBonus = Double.valueOf(totalAmount.doubleValue() * (refererPromotionSettleInfo.getFifthLevelProportion().doubleValue() / 100.0D)).doubleValue();
                double accountBalance = referer.getAccountBalance().doubleValue() - vipSerivceBonus;

                double fifthLevelCumulativeIncome = refererPromotionSettleInfo.getFifthLevelCumulativeIncome().doubleValue() - vipSerivceBonus;
                double cumulativeIncome = refererPromotionSettleInfo.getCumulativeIncome().doubleValue() - vipSerivceBonus;
                refererPromotionSettleInfo.setFifthLevelCumulativeIncome(Double.valueOf(fifthLevelCumulativeIncome > 0.0D ? fifthLevelCumulativeIncome : 0.0D));
                refererPromotionSettleInfo.setCumulativeIncome(Double.valueOf(cumulativeIncome > 0.0D ? cumulativeIncome : 0.0D));
                this.bUserPromotionSettleInfoService.updateById(refererPromotionSettleInfo);

                backAccountBalance(referer.getUserId(), referer
                                .getAccountBalance(),
                        Double.valueOf(accountBalance > 0.0D ? accountBalance : 0.0D),
                        Double.valueOf(-vipSerivceBonus), userInfo,

                        Integer.valueOf(5),
                        Integer.valueOf(refererPromotionSettleInfo.getFifthLevelProportion().intValue()), totalAmount);
                try
                {
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserInviteIncomeInfoMapper");
                    HttpGetPostUtils.delCache(this.serviceUrls, "UserPromotionSettleInfoMapper");
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
    }

    private void backAccountBalance(Integer refererUserId, Double beforeBalance, Double afterBalance, Double vipSerivceBonus, BUserInfoEntity fromUser, Integer level, Integer levelProportion, Double totalAmount)
    {
        BUserInfoEntity updateRefererObj = new BUserInfoEntity();
        updateRefererObj.setUserId(refererUserId);
        updateRefererObj.setAccountBalance(afterBalance);
        this.bUserInfoService.updateById(updateRefererObj);

        BUserInviteIncomeInfoEntity userInviteIncomeInfo = new BUserInviteIncomeInfoEntity();
        userInviteIncomeInfo.setUserId(refererUserId);
        userInviteIncomeInfo.setBeforeBalance(beforeBalance);
        userInviteIncomeInfo.setAfterBalance(afterBalance);
        userInviteIncomeInfo.setIncome(vipSerivceBonus);

        userInviteIncomeInfo.setFromUserId(fromUser.getUserId());
        userInviteIncomeInfo.setFromNickName(fromUser.getNickName());
        userInviteIncomeInfo.setFromAvatarUrl(fromUser.getAvatarUrl());
        userInviteIncomeInfo.setCreateTime(DateUtil.getCurDate());
        userInviteIncomeInfo.setLevel(level);
        userInviteIncomeInfo.setLevelProportion(levelProportion);
        userInviteIncomeInfo.setBase(totalAmount);

        this.bUserInviteIncomeInfoService.save(userInviteIncomeInfo);
    }
}
